﻿
// Condition: 14. Write methods to calculate minimum, maximum, average, sum and produst of given
//            set of integer numbers. Use variable number of arguments.

using System;




class Multitask
{

    static void Sum(int[] array)
    {
        
        int sum = 0;
        for (int i = 0; i < array.Length; i++)
        {
            sum += array[i];
        }

        Console.WriteLine("The sum of given integers is: {0}",sum);
    }

    static void Product(int[] array)
    {
        int product = 1;
        for (int i = 0; i < array.Length; i++)
        {
            product *= array[i];
        }

        Console.WriteLine("The product of given integers is: {0}", product);
    }

    static void Max(int[] array)
    {
        for (int i = 0; i < array.Length-1; i++)
        {
            for (int j = i+1; j < array.Length; j++)
            {
                if (array[i] < array[j])
                {
                    array[i] = array[i] + array[j];
                    array[j] = array[i] - array[j];
                    array[i] = array[i] - array[j];
                }
            }
        }

        Console.WriteLine("The maximum of given integers is: {0}", array[0]);
    }

    static void Min(int[] array)
    {
        for (int i = 0; i < array.Length - 1; i++)
        {
            for (int j = i + 1; j < array.Length; j++)
            {
                if (array[i] < array[j])
                {
                    array[i] = array[i] + array[j];
                    array[j] = array[i] - array[j];
                    array[i] = array[i] - array[j];
                }
            }
        }

        Console.WriteLine("The minimum of given integers is: {0}", array[array.Length-1]);
    }

    static void Main(string[] args)
    {
        // define numbers
        Console.Write("Enter number of arguments: ");
        int argument = int.Parse(Console.ReadLine());
        int[] argArray = new int[argument];


        for (int i = 0; i < argument; i++)
        {
            Console.Write("Number[{0}]= ",i+1);
            argArray[i] = int.Parse(Console.ReadLine());
        }
        // create menu to choose different methods
        Console.WriteLine("Menu: ");
        Console.WriteLine("Finding the minimum of numbers press 1.");
        Console.WriteLine("Finding the maximum of numbers press 2.");
        Console.WriteLine("Calculate the sum of numbers press 3");
        Console.WriteLine("Calculate the product of numbers press 4");
        int menu = int.Parse(Console.ReadLine());
        if (menu == 1)
        {
            Min(argArray);
        }
        else if (menu == 2)
        {
            Max(argArray);
        }
        else if (menu == 3)
        {
            Sum(argArray);
        }
        else if (menu == 4)
        {
            Product(argArray);
        }
 
    }
}

